package cn.school.controller.student;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.student.service.EntranceProcessService;
import cn.school.student.vo.EntranceProcessVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "迎新流程定义")
@RequestMapping("/entrance")
public class EntranceProcessController {

    @Autowired
    private EntranceProcessService entranceProcessService;

    @ApiOperation("list => 分页查询")
    @PostMapping("/list")
//    @PreAuthorize("@ss.hasPermi('consult:enroll:list')")
    public CommonResult<CommonPage<EntranceProcessVO>> findEntranceProcessPageList(@RequestBody EntranceProcessVO vo){
        IPage<EntranceProcessVO> pageList = entranceProcessService.findEntranceProcessPageList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("edit => 新增or修改")
    @PostMapping("/edit")
    public CommonResult<CommonPage<EntranceProcessVO>> addOrUpdateEntranceProcess(@RequestBody EntranceProcessVO vo){
        int num = entranceProcessService.addOrUpdateEntranceProcess(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("delete => 删除")
    @PostMapping("/delete")
    public CommonResult<CommonPage<EntranceProcessVO>> deleteEntranceProcessBatch(@RequestBody List<Long> ids){
        int num = entranceProcessService.deleteEntranceProcessBatch(ids);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(" details=> 详情")
    @PostMapping("/details")
    public CommonResult<EntranceProcessVO> findEntranceProcessDetailById(@RequestBody EntranceProcessVO vo){
        EntranceProcessVO entranceProcessVO = entranceProcessService.findEntranceProcessDetailById(vo.getId());
        return CommonResult.success(entranceProcessVO);
    }

    @ApiOperation("updateStstus=> 修改状态")
    @PostMapping("/updateStatus")
    public CommonResult<EntranceProcessVO> batchUpdateStatus(@RequestBody List<EntranceProcessVO> vo){
        int num = entranceProcessService.batchUpdateStatus(vo);
        return CommonResult.success();
    }



}
